package com.borball.test.functional;

import javax.sql.DataSource;

import org.apache.commons.dbcp.BasicDataSource;

import com.borball.store.util.PropertiesUtils;

public class DataSourceFactory {

	private static DataSourceFactory instance;
	private BasicDataSource ds = null;

	private DataSourceFactory() {
		if (ds == null) {
			ds = new BasicDataSource();
			try {
				ds.setDriverClassName(PropertiesUtils.loadProperties("ds-mysql.properties").getProperty("jdbc.driver"));
				ds.setUrl(PropertiesUtils.loadProperties("ds-mysql.properties").getProperty("jdbc.url"));
				ds.setUsername(PropertiesUtils.loadProperties("ds-mysql.properties").getProperty("jdbc.username"));
				ds.setPassword(PropertiesUtils.loadProperties("ds-mysql.properties").getProperty("jdbc.password"));
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

		}
	}

	public static DataSourceFactory getInstance() {
		if (null == instance) {
			instance = new DataSourceFactory();
		}
		return instance;
	}

	public DataSource getDataSource() {
		return ds;
	}

}
